#ifndef SHOP_H
#define SHOP_H

#include <Invoice.h>
#include <Product.h>
#include <Customer.h>
#include <Proveider.h>

#include <QString>
#include <vector>
#include <QFile>

namespace ecocity
{

class Shop
{

public:

    Shop( const QString& csv_products,
          const QString& csv_customers,
          const QString& csv_invoices );

    static QStringList customer_types( );

    void add_product( const Product& product );
    void add_customer( const Customer& customer );
    void add_invoice( const Invoice& invoice );

    void set_products( const std::vector< Product >& products );

    bool update_product( const Product& product );

    // TODO see if those should be private
    // and where they are used call shop.create_invoice( QTextStream)
    Customer *get_customer( int id );
    Product* get_product( const QString& name );
    Product* get_product( int id );

    bool remove_customer( const QString& name,
                          const QString& address,
                          Customer::TYPE type );
    bool remove_product( const QString& name,
                         const Proveider& proveider,
                         Product::PRICE_TYPE price_type );

    bool remove_invoice( const QString& customer_name,
                         const QDate& date,
                         float total_price,
                         float total_profit );

    const std::vector< Product >& products( ) const;
    const std::vector< Customer >& customers( ) const;
    const std::vector< Invoice >& invoices( ) const;
    const std::vector< Proveider >& proveiders( ) const;

    std::vector< Invoice > invoices( const Customer& cusomer ) const;

    Customer customer( const QString& customer_name ) const;

private:

    bool parse_invoices( const QString& file_invoice_csv );
    bool parse_invoices( QFile& stream, const char separator = ';' );
    bool parse_invoices_line( const QString& file_invoice_csv, const char separator = ';' );

    Customer get_customer( const QString& name );

    std::vector< Product > get_products_with_names( const QStringList& product_list );

private:

    // Using ASSOCIATION:
    // Shop owns the Products/Customer/Invoice objects which means that
    // Products/Customers/Invoices can not belong to any other object
    //
    // Product/Customer/Invoice objects can have its own time life, if a Shop
    // gets deleted, the Product/Customer/Invoice object does not die.
    std::vector< Product > m_products;
    std::vector< Customer > m_customers;
    std::vector< Invoice > m_invoices;
    std::vector< Proveider > m_proveiders;
};

}      // namespace ecocity

#endif // SHOP_H
